//
//  HNSH_ShopApplyBankInfoView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/5.
//

#import "HNSH_ShopApplyBankInfoView.h"

//cell
#import "HNSH_ShopApplyInputCell.h"
#import "HNSH_ShopApplySelectCell.h"
#import "HNSH_ShopApplyUpLoadCell.h"


@interface HNSH_ShopApplyBankInfoView ()<UITableViewDelegate,UITableViewDataSource>

/* tableView */
@property (nonatomic, strong) UITableView *tableView;

/* listAry */
@property (nonatomic, strong) NSArray *listAry;

@end

static NSString *HNSH_ShopApplyInputCellID = @"HNSH_ShopApplyInputCellID";
static NSString *HNSH_ShopApplySelectCellID = @"HNSH_ShopApplySelectCellID";
static NSString *HNSH_ShopApplyUpLoadCellID = @"HNSH_ShopApplyUpLoadCellID";

@implementation HNSH_ShopApplyBankInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

#pragma mark lazy
- (NSArray *)listAry {
    if (!_listAry) {
        _listAry = @[@{@"title":@"开户银行：",@"des":@"请输入开户银行名称"},
                     @{@"title":@"开户银行支行名称：",@"des":@"请输入开户银行支行名称"},
                     @{@"title":@"对公银行账号：",@"des":@"请输入对公银行账号"}];
    }
    return _listAry;
}

- (void)setSubmitModel:(HNSH_ShopSubmitModel *)submitModel {
    _submitModel = submitModel;
    [self.tableView reloadData];
}

- (void)configUI {
    
    [self addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    self.tableView.backgroundColor = [UIColor appWhiteLabelColor];
    
    [self.tableView registerClass:[HNSH_ShopApplyInputCell class] forCellReuseIdentifier:HNSH_ShopApplyInputCellID];
    [self.tableView registerClass:[HNSH_ShopApplySelectCell class] forCellReuseIdentifier:HNSH_ShopApplySelectCellID];
    [self.tableView registerClass:[HNSH_ShopApplyUpLoadCell class] forCellReuseIdentifier:HNSH_ShopApplyUpLoadCellID];
}
#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.listAry.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HNSH_ShopApplyInputCell *cell = [tableView dequeueReusableCellWithIdentifier:HNSH_ShopApplyInputCellID];
    NSDictionary *dict = self.listAry[indexPath.row];
    cell.title = dict[@"title"];
    cell.placeholder = dict[@"des"];
    if (indexPath.row == 0) {//开户银行 线上
        cell.textField.text = self.submitModel.bank_name;
    } else if (indexPath.row == 1) {//开户银行支行 线上
        cell.textField.text = self.submitModel.bank_branch_name;
    } else if (indexPath.row == 2) {//对公银行账号 线上
        cell.textField.text = self.submitModel.bank_card_no;
    }
    WeakSelf(weakSelf);
    cell.inputBlock = ^(NSString * _Nonnull inputString) {
        if (indexPath.row == 0) {//开户银行 线上
            weakSelf.submitModel.bank_name = inputString;
        } else if (indexPath.row == 1) {//开户银行支行 线上
            weakSelf.submitModel.bank_branch_name = inputString;
        } else if (indexPath.row == 2) {//对公银行账号 线上
            weakSelf.submitModel.bank_card_no = inputString;
        }
    };
    return cell;
}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight-kNavBarAndStatusBarHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.estimatedRowHeight = 44;
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
        
    }
    return _tableView;
}


@end
